package com.dragon.repository.domain.dto;

import com.dragon.common.util.BeanUtils;
import com.dragon.repository.entity.Department;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * @author sy
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class DepartmentDTO {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "部门id")
    private Integer id;

    @ApiModelProperty(value = "部门名称")
    private String name;

    @ApiModelProperty(value = "上级id")
    private Integer pid;

    @ApiModelProperty(value = "是否启用：1启用0禁用")
    private Integer enable;

    @ApiModelProperty(value = "部门说明")
    private String remark;

    @ApiModelProperty(value = "添加时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date createTime;

    @ApiModelProperty(value = "修改时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date updateTime;


    public DepartmentDTO() {}

    public DepartmentDTO(Department entity) {
        BeanUtils.copyProperties(entity,this);
    }

    public static DepartmentDTO convert(Department entity) {
        return new DepartmentDTO(entity);
    }

    public static List<DepartmentDTO> convertList(List<Department> list) {
        List<DepartmentDTO> resultList = new ArrayList<>();
        for (Department entity : list) {
            resultList.add(new DepartmentDTO(entity));
        }
        return resultList;
    }}
